%w stand for width of a piece of board
% l stand for length of table
% chord stand for every length of pattern
% alp stand for the degree of table when it is fixed
%position stand for the position of screw in the most out leg
%?????????---? ??
%????????????---????
function [alpha legL xtop ytop ztop xbottom ybottom zbottom ] = actionCal(w,h,alp,chord,position,thick)


n = length(chord);  % number of board

%1 vector: 1:chord 2:alpha 3:legL 4:screw
legL(n) = getL(alp,h);
l = legL(n) + chord(n);

legL =  l - chord;  % legL stand for every length of table leg: is a vector
alpha = zeros(1,n);    % alpha stand for the degree between every board and desktop,is a vector,from center to boarder is 1-n;
alpha(n) = alp;
if(position < 1)
    screw(n) = legL(n) * position;
else
    return;
end

%2 get every coordinate of top point
t = 1:n;
xtop = (t - 1) * w;
ytop = chord + thick;
ztop = ones(1,n) * thick;

%3 get every coordinate of screw potition
xscrew = xtop;

yscrew = ones(1,n) * screw(n) * cos(alpha(n)) + ytop(n);

zscrew = ones(1,n) * screw(n) * sin(alpha(n)) + ztop(n);

%4 get every alpha of leg to desktop
deltaZ = zscrew - ztop;
deltaY = yscrew - ytop;
for i = 1:n -1
    tangent = deltaZ(i) / deltaY(i);
    deg = atan(tangent);
    if(deg > 0 )
        alpha(i) = deg;
    else
        alpha(i) = pi - abs(deg);
    end
end

%5 get every coordinate of bottom point
xbottom = xtop;
ybottom = legL .* cos(alpha) + ytop;
zbottom = legL .* sin(alpha) + ztop;
if( any(ybottom < 0) )
    disp('error y coordinate');
    return;
end

